<template>
	<div id="xgks" class="el-tab-boder" style="width: 100%;margin-bottom: 16px;">
		<div style="font-size: 15px;width: 1300px;margin: auto;margin-top: 10px;">
			<span>方案设计</span> <span style="margin-left: 5px;margin-right: 5px;">></span> <span>管理方案</span> <span style="margin-left: 5px;margin-right: 5px;">></span> <span>选科方案</span></br>
			<img src="../img/nan.png" style="width: 20px;vertical-align: middle;" v-show="user.sex==0"/>
			<img src="../img/nv.png" style="width: 20px;vertical-align: middle;" v-show="user.sex==1"/>
			<span style="display: inline-block;margin-top: 5px;margin-left: 0.5em;">{{user.name}}</span>
		</div>
		<div class="d2">
			<el-tabs v-model="activeName"  @tab-click="condition">
			            <el-tab-pane label="按选科组合查询" name="first" :key="'first'">
							<div id="xk">
								<span style="font-size: 15px;font-weight: bold;margin-right: 0.5em;">院校名称</span>
								<el-row class="demo-autocomplete" style="display: inline-block;width:20%;">
								  <el-col :span="12" style="display: inline-block;width:100%;height: 20px;">
								    <el-autocomplete
								      class="inline-input"
								      v-model="school"
								      :fetch-suggestions="querySearch1"
								      placeholder="请输入内容"
								      :trigger-on-focus="false"
									  size="mini"
									  style="width: 100%;"
								    ></el-autocomplete>
								  </el-col>
								  </el-row>
								  <span style="font-size: 15px;font-weight: bold;margin-right: 0.5em;margin-left: 0.5em;">专业名称</span>
								  <el-row class="demo-autocomplete" style="display: inline-block;width:20%;height: 20px;">
								  	  <el-col :span="12" style="display: inline-block;width:100%;height: 20px;">
								  	    <el-autocomplete
								  	      class="inline-input"
								  	      v-model="major"
								  	      :fetch-suggestions="querySearch"
								  	      placeholder="请输入内容"
								  	      :trigger-on-focus="false"
								  		  size="mini"
								  		  style="width: 100%;"
								  	    ></el-autocomplete>
								  	  </el-col>
								  	  </el-row>
								<el-form :inline="true"  class="demo-form-inline"
									style="padding: 0;margin: 0;height: 40px;margin-top: 5px;">
									<el-form-item label="首选科目" style="font-weight: bold;">
										<el-radio-group v-model="schoice">
											<el-radio label="W">物理</el-radio>
											<el-radio label="L">历史</el-radio>
										</el-radio-group>
									</el-form-item>
									<el-form-item label="再选科目" style="font-weight: bold;margin-left: 30px;">
										<el-checkbox-group 
										    v-model="cchoice"
										    :max="2">
										    <el-checkbox v-for="zx in zxkm" :label="zx.value" :key="zx.value">{{zx.label}}</el-checkbox>
										  </el-checkbox-group>
									</el-form-item>
									<el-form-item label="批次" style="font-weight: bold;margin-left: 30px;">
										<el-radio-group v-model="arrangement">
											<el-radio label="1">本科</el-radio>
											<el-radio label="2">专科</el-radio>
										</el-radio-group>
									</el-form-item>
								</el-form>
							</div>
			                    <div style="height: 145px;" id="fx">
									<div style="width: 100%;margin: auto;">
										<span style="font-weight: bold;font-size: 15px;">所在省份</span>
										<ul class="ul2" v-for="item in cities">
											<li style="line-height: 30px;">
												<el-checkbox-group v-model="checkedCities">
													<el-checkbox style="margin-left:0;font-size: 15px;padding: 0;" :label="item.value"
														:key="item.value"  @change="sfclick(item.label,$event)">{{item.label}}</el-checkbox>
												</el-checkbox-group>
											</li>
										</ul>
									</div>
									<div style="width: 100%;margin: auto;height:20px;margin-top: 5px;">
										<span style="font-weight: bold;font-size: 15px;">院校类型</span>
										<div style="display: inline-block;width: 58%;">
										<ul class="ul2" v-for="item in SchoolTypes">
											<li>
												<el-checkbox-group v-model="checkedSchoolTypes">
													<el-checkbox style="margin-left:0;font-size: 15px;padding: 0;" :label="item.value"
														:key="item.value" @change="schooltypeclick(item.value,$event)">{{item.value}}</el-checkbox>
												</el-checkbox-group>
											</li>
										</ul>
										</div>
										<div style="display: inline-block;">
										<span style="font-weight: bold;font-size: 15px;">博硕资格</span>
										<ul class="ul2" v-for="item in Qualifications">
											<li>
												<el-checkbox-group v-model="checkedQualifications">
													<el-checkbox style="margin-left:0;font-size: 15px;padding: 0;" :label="item.value"
														:key="item.value" @change="qualificationsclick(item.value,$event)">{{item.label}}</el-checkbox>
												</el-checkbox-group>
											</li>
										</ul>
											</div>
									</div>
									<div style="width: 100%;margin: auto;height: 40px;">
										<span style="font-weight: bold;font-size: 15px;">院校层级</span>
										<div style="display: inline-block;width:58%;">
										<ul class="ul2" v-for="item in Hierarchys">
											<li>
												<el-checkbox-group v-model="checkedHierarchys">
													<el-checkbox style="margin-left:0;font-size: 15px;padding: 0;" :label="item.value"
														:key="item.value" @change="hierarchysclick(item.value,$event)">{{item.label}}</el-checkbox>
												</el-checkbox-group>
											</li>
										</ul>
										</div>
										<span style="font-weight: bold;font-size: 15px;">办学性质</span>
										<ul class="ul2" v-for="item in natures">
											<li>
												<el-checkbox-group v-model="checkedNatures">
													<el-checkbox style="margin-left:0;font-size: 15px;padding: 0;" :label="item.value"
														:key="item.value" @change="natureclick(item.value,$event)">{{item.label}}</el-checkbox>
												</el-checkbox-group>
											</li>
										</ul>
										<button style="margin-left: 1%;cursor: pointer;" @click="getNewSchool()" class="btn">查询</button>
										<button style="margin-left: 0.5%;cursor: pointer;" @click="condition()" class="btn">重置</button>
									</div>
			                    </div>
			            </el-tab-pane>
			
			            <el-tab-pane label="按选科要求查询" name="second" :key="'second'">
			                    <div style="height: 60px;">
									<span style="font-size: 15px;font-weight: bold;margin-right: 0.5em;">选科要求</span>
										<el-select
										    v-model="courseRequire"
										    multiple
										    collapse-tags
										    placeholder="请选择"
											style="height: 28px;line-height: 28px;">
										    <el-option
										      v-for="item in yaoqiu"
										      :key="item.dictValue"
										      :label="item.dictName"
										      :value="item.dictValue">
										    </el-option>
										  </el-select>
			                       <button style="margin-left: 5px;cursor: pointer;" @click="getNewSchool()" class="btn">查询</button>
								   <button style="margin-left: 0.5%;cursor: pointer;" @click="condition()" class="btn">重置</button>
			                    </div>
			            </el-tab-pane>
			        </el-tabs>
		
		</div>
		<div style="width: 1300px;min-width: 1300px;margin: auto;overflow:auto;" >
			<span style="margin-bottom: 20px;display: inline-block;font-size: 15px;font-weight: bold;">检索结果<span style="margin-left: 10px;font-weight: normal;">{{count}}</span></span>
			<!-- 普通 -->
			<el-table v-loading="loading" ref="multipleTable" :data="tableData"
				height="800px"
				:header-cell-style="{textAlign: 'center',}" :cell-style="cellStyle" border 
				style="width: 100%;color: black;overflow: auto;font-size: 15px;">
				<el-table-column prop="newSchoolid" label="学校标识码" min-width="14px">
					<template slot-scope="props">
						<span @click="clickTable(props.row)" style="cursor: pointer;">{{props.row.newSchoolid}}</span>
					</template>
				</el-table-column>
				<el-table-column prop="schoolName" label="院校名称"  min-width="40px">
					<template slot-scope="scope">
						<span>{{scope.row.schoolName}}</span>
					</template>
				</el-table-column>
				<el-table-column prop="" label="办学性质|院校类型|主管部门|所在城市|院校排名|院校层级|博硕资格">
					<template slot-scope="scope">
						{{scope.row.nature==1?"公办":(scope.row.nature==2?"民办":"合办")}}
						{{scope.row.schoolType}}
						{{scope.row.manager}}
						{{scope.row.city}}
						排名{{scope.row.sortNum}}
						<span style="width: 0.5em;display: inline-block;"></span>
						{{scope.row.hierarchysName}}
						<span style="width: 0.5em;display: inline-block;"></span>
						{{scope.row.qualificationsName}}
					</template>
				</el-table-column>
				<el-table-column prop="cankao_li" label="参考分(理)" min-width="12px">
				</el-table-column>
				<el-table-column prop="cankao_wen" label="参考分(文)" min-width="12px">
				</el-table-column>
				<el-table-column prop="" label="选科要求" min-width="20px">
				</el-table-column>
				<el-table-column prop="" label="操作" min-width="14px">
					<template slot-scope="scope">
						<!-- <span @click="statusChange(scope.$index,'收藏')">{{scope.row.schemeName?"已收藏":"收藏"}}</span> -->
						<span v-show="!scope.row.schemeName" @click="statusChange(scope.$index,'收藏')" >收藏</span>
						<span v-show="scope.row.schemeName" style="color: coral;">已收藏</span>
						<!-- :class="scope.row.schemeName!=''?'qux':'not-qux'" -->
						<span style="margin-left: 10px;"@click="statusChange(scope.$index,'取消')"
						
						>取消</span>
					</template>
				</el-table-column>
				<el-table-column type="expand" width="1">
					<template slot-scope="props">
						<el-table :data="props.row.children" style="width: 100%;font-size: 15px;" id="table"
							:header-cell-style="{textAlign: 'center',backgroundColor:'#fff2f3'}" :cell-style="cellStyles"  border v-loading="loadings" >
							<el-table-column label="专业代码" prop="majorCode" min-width="12px"></el-table-column>
							<el-table-column label="专业(类)名称" prop="majorName" min-width="40px"></el-table-column>
							<el-table-column label="包含专业" prop="majorList"></el-table-column>
							<el-table-column label="" prop="" min-width="12px"></el-table-column>
							<el-table-column label="" prop="" min-width="12px"></el-table-column>
							<el-table-column label="选科要求" prop="courseRequire" min-width="20px"></el-table-column>
							<el-table-column label="操作" prop="" min-width="14px">
								<template slot-scope="propss">
									<span v-show="!propss.row.sort" @click="majorchange(props.$index,propss.$index,props.row,propss.row,'收藏')" style="color: orangered;">收藏</span>
									<span v-show="propss.row.sort">已收藏</span>
									 <span style="margin-left: 10px; "@click="majorchange(props.$index,propss.$index,props.row,propss.row,'取消')"
									 :class="propss.row.sort!=null?'qux':'not-qux'"
									 >取消</span>
								</template>
							</el-table-column>
							<el-table-column width="1"></el-table-column>
						</el-table>
					</template>
				</el-table-column>
				</el-table-column>
			</el-table>
			
		</div>
		<el-dialog title="新建方案" :visible="dialogVisible" width="800px" :close-on-click-modal="false" :show-close="false">
			<el-form ref="form" v-model="form"  style="margin: auto;width: 600px;text-align: center;">
				<el-form-item prop="name">
					*方案名称
					<el-input v-model="form.name" style="width: 300px;" @keydown.native="keydown($event)"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="saveSchemes()" style="">立即创建</el-button>
					<el-button type="primary" @click="fh()" style="">上一步</el-button>
				</el-form-item>
			</el-form>
		
		</el-dialog>
		<div id="npt" style="z-index: 99999;">
			<el-button style="background-color: orange;margin-top: 20px;" @click="handleClick()">预览</el-button></br>
			<el-button style="background-color: #1264ff;margin-top: 20px;" @click="empty()">清空</el-button>
		</div>
	</div>
</template>

<script>
	import {
		request
	} from "../util/request.js"
	const cityOptions = [
		{label:'不限',value:'不限'},{label:'陕西',value:'陕西省'},{label:'安徽',value:'安徽省'},{label:'北京',value:'北京市'},{label:'重庆',value:'重庆市'},
		{label:'福建',value:'福建省'},{label:'广东',value:'广东省'},{label:'广西',value:'广西'},{label:'甘肃',value:'甘肃省'},{label:'贵州',value:'贵州省'},
		{label:'河北',value:'河北省'},{label:'河南',value:'河南省'},{label:'海南',value:'海南省'},{label:'湖北',value:'湖北省'},{label:'湖南',value:'湖南省'},
		{label:'黑龙江',value:'黑龙江省'},{label:'吉林',value:'吉林省'},{label:'江苏',value:'江苏省'},{label:'江西',value:'江西省'},{label:'辽宁',value:'辽宁省'},
		{label:'内蒙古',value:'内蒙古'},{label:'宁夏',value:'宁夏'},{label:'青海',value:'青海省'},{label:'上海',value:'上海市'},
		{label:'四川',value:'四川省'},{label:'山东',value:'山东省'},{label:'山西',value:'山西省'},{label:'天津',value:'天津市'},{label:'西藏',value:'西藏'},
		{label:'新疆',value:'新疆'},{label:'云南',value:'云南省'},{label:'浙江',value:'浙江省'},{label:'其他',value:'其他'}
	]
	const SchoolTypeOptions = [
		{label:'不限',value:'不限'},{label:'综合',value:'综合'},{label:'工科',value:'工科'},{label:'财经',value:'财经'},{label:'农业',value:'农业'},{label:'林业',value:'林业'},
		{label:'医药',value:'医药'},{label:'师范',value:'师范'},{label:'体育',value:'体育'},{label:'政法',value:'政法'},{label:'民族',value:'民族'},
		{label:'语言',value:'语言'},{label:'艺术',value:'艺术'},{label:'军事',value:'军事'},{label:'其他',value:'其他'}
	]
	const natureOptions = [
		{label:'不限',value:'不限'},{label:'公办',value:'1'},{label:'民办',value:'2'},{label:'合办',value:'3'}
	]
	const HierarchyOptions = [
		{label:'不限',value:'不限'},{label:'双一流',value:'1'},{label:'中央直管',value:'2'},{label:'985',value:'3'},{label:'211',value:'4'},{label:'双高计划',value:'5'},{label:'国家示范(骨干)',value:'6'}
	]
	const QualificationsOptions = [
		{label:'不限',value:'不限'},{label:'硕士点',value:'1'},{label:'博士点',value:'2'},{label:'研究生院',value:'3'},{label:'自划线',value:'4'},{label:'推免资格',value:'5'}
	]
	const zxkms = [
		{label:'化学',value:'H'},{label:'生物',value:'S'},{label:'政治',value:'Z'},{label:'地理',value:'D'}
	]
	export default {
		data() {
			return {
				sort:null,
				scheme: [],
				form: {
					name: ''
				},
				dialogVisible:true,
				zxkm:zxkms,
				arrangement:'1',
				activeName: "first",
				count:null,
				props: {
					multiple: true
				},
				programmes: [],
				loading: true,
				value: [],
				tableData: [],
				isLoad: false,
				major: '',
				school: '',
				childrenData:[],
				childrenData:[],
				schoice:'W',
				options:null,
				schoolNames:null,
				cchoice:['H','S'],
				courseRequire: null,
				type:null,
				yaoqiu: [],
				cities: cityOptions,
				SchoolTypes: SchoolTypeOptions,
				natures: natureOptions,
				Hierarchys: HierarchyOptions,
				Qualifications: QualificationsOptions,
				checkedCities: ['不限'],
				checkedSchoolTypes: ['不限'],
				checkedNatures: ['不限'],
				checkedHierarchys: ['不限'],
				checkedQualifications: ['不限'],
				pageObject: {
					pageNum: 1,
					pageSize: 40,
					total: 0
				},
			}
		},
		methods: {
			//执行点击行调用的方法，展开和折叠行
			 clickTable(row,index,e){
			 	let state=false
			 	// console.log("学校内容"+JSON.stringify(row))
			 	this.tableData.forEach(s=>{
			 		if(s.newSchoolid==row.newSchoolid){
			 			if(s.children!=null){
			 				state=true
			 				s.children=null
			 			}
			 		}
			 	})
			 	if(state==false){
			 		this.getSchoolMajor(row)
			 	}else{
			 		this.$refs.multipleTable.toggleRowExpansion(row)
			 	}
			  },
			  getSchoolMajor(row) {
			  	this.loadings=true
			  	this.pageObject.schoolCode=row.newSchoolid
			  	this.pageObject.major=this.major
			  	this.pageObject.school=this.school
			  	this.pageObject.courseRequire=this.courseRequire
			  	this.pageObject.arrangement=this.arrangement
			  	this.pageObject.schoice=this.schoice
			  	this.pageObject.cchoice=this.cchoice
			  	request({
			  		method: 'post',
			  		url: 'electiveCourseInfo/getSchoolMajor',
			  		data:this.pageObject
			  	}).then(res => {
			  		for(let i=0;i<this.tableData.length;i++){
			  			if(this.tableData[i].newSchoolid==row.newSchoolid){
			  				this.$set(this.tableData[i],"children",res.data)
							for(let j=0;j<this.childrenData.length;j++){
								if(this.childrenData[j].schoolCode==this.tableData[i].newSchoolid){
									if(this.childrenData[j].majorList!=null){
										this.childrenData[j].majorList.forEach(m=>{
											this.tableData[i].children.forEach(c=>{
												if(m.id==c.id){
													c.sort=m.sort
												}
											})
										})
									}
								}
							}
			  				console.log("数据"+this.tableData[i].children)
			  			}
			  		}
			  		this.$forceUpdate()
			  		this.loadings=false
			  		this.$refs.multipleTable.toggleRowExpansion(row)
			  		
			  	})
			  },
			empty(){
				this.childrenData=[]
				this.scheme = []
				this.scheme.push({
					"programmeName": this.programmes != null && this.programmes.length > 0 ? this
						.programmes[0].programmeName : this.form.name,
					"programmeId": this.programmes != null && this.programmes.length > 0 ? this
						.programmes[0].programmeId : this.programmeId,
					"stuId": this.stuId
				})
				request({
					method: 'post',
					url: 'stuNewSchoolScheme/saveNewSchoolScheme',
					data: this.scheme
				}).then(res => {
					if (res.code == 0 || res.code == 200) {
						this.$message({
							message: '保存成功！',
							type: 'success'
						});
						this.programmeId = res.data.list[0].programmeId
					} else {
						this.$message({
							message: res.msg,
							type: 'error'
						});
					}
					this.getNewSchool()
				})
			},
			handleClick(){
				const infos = this.programmes[0];
				localStorage.setItem('volunteer', JSON.stringify(infos))
				this.$router.push({
					path:"/XkPreview",
					params: {
						info: infos
					}
				})
			},
			saveScheme() {
				for (let i = 0; i < this.childrenData.length; i++) {
					if (this.childrenData[i].schoolCode === null || this.childrenData[i].schoolCode === "") {
						this.childrenData.splice(i, 1);
					}
					console.log("删除了")
				}
				console.log("处理后"+JSON.stringify(this.childrenData))
					this.scheme = []
					if (this.childrenData != undefined && this.childrenData.length > 0) {
						this.childrenData.forEach(i => {
							this.scheme.push({
								"schoolCode": i.schoolCode,
								"schoolName": i.schoolName,
								"majorList": i.majorList ? JSON.stringify(i.majorList).toString() : null,
								"programmeName": this.programmes != null && this.programmes.length > 0 ? this
									.programmes[0].programmeName : this.form.name,
								"schemeName": i.schemeName,
								"programmeId": this.programmes != null && this.programmes.length > 0 ? this
									.programmes[0].programmeId : this.programmeId,
								"stuId": this.stuId,
								"sort":this.programmes != null && this.programmes.length > 0 ? this
									.programmes[0].sort : this.sort,
							})
						})
					} else {
							this.$message({
								message: '请至少选择一个志愿！',
								type: 'warning'
							});
							throw Error;
					}
					request({
						method: 'post',
						url: 'stuNewSchoolScheme/saveNewSchoolScheme',
						data: this.scheme
					}).then(res => {
						if (res.code == 0 || res.code == 200) {
							this.$message({
								message: '保存成功！',
								type: 'success'
							});
							this.programmeId = res.data.list[0].programmeId
							this.sort=res.data.list[0].sort
							// this.getNewSchool()
						} else {
							this.$message({
								message: res.msg,
								type: 'error'
							});
						}
					})
				
			
			},
			saveSchemes(){
					if(this.form.name!=null&&this.form.name!=""){
						this.scheme.push({
							"programmeName": this.form.name,
							"stuId": this.stuId,
						})
					}else{
							this.$message({
							          message: '方案名称不能为空！',
							          type: 'warning'
							        });
									return;
					}
					request({
						method: 'post',
						url: 'stuNewSchoolScheme/saveNewSchoolScheme',
						data: this.scheme
					}).then(res => {
						if (res.code == 0 || res.code == 200) {
							this.$message({
								message: '保存成功！',
								type: 'success'
							});
							this.programmeId=res.data.list[0].programmeId
							this.sort=res.data.list[0].sort
							this.dialogVisible=false
							this.updates(res.data.list)
						} else {
							this.$message({
								message: res.msg,
								type: 'error'
							});
						}
					})
			
			},
			updates(row){
				const programme = row;
				this.$router.push({
					path: '/toNewSchoolProgramme',
					query: {
						programme: JSON.stringify(programme)
					}
				})
			},
			fh(){
				this.$router.push({
					path:"/XkAdministration"
				})
			},
			keydown(e) {
				if (e.keyCode == 32) {
					e.returnValue = false
				}
			},
			majorchange(sindex, zindex, srow, zrow, label) {
				if (label == "取消") {
					for (var i = 0; i < this.childrenData.length; i++) {
						for (var j = 0; j < this.childrenData[i].majorList.length; j++) {
							if (this.childrenData[i].majorList[j].id == this.tableData[sindex].children[zindex]
								.id) {
								this.childrenData[i].majorList.splice(j, 1);
							}
						}
					}
					this.tableData[sindex].children[zindex].sort = null
				}else if(label=="收藏"){
					console.log("学校"+this.tableData[sindex].schemeName)
					if (this.tableData[sindex].schemeName!=null&&this.tableData[sindex].schemeName!='') {
						this.childrenData.forEach(i => {
							if (srow.newSchoolid == i.schoolCode) {
								if (!i.majorList) {
									i.majorList = []
								}
								i.majorList.push({
									"id":zrow.id,
									"sort": label,
									"majorName": zrow.majorName,
									"courseRequire":zrow.courseRequire
								})
							}
						})
						this.$set(this.tableData[sindex].children[zindex], 'sort', label)
						this.tableData[sindex].children[zindex].sort = label
					} else {
						this.$message({
							message: '请先选择学校',
							type: 'warning'
						});
						return false;
					}
				}
				this.saveScheme()
			},
			statusChange(index, val) {
				if (val == "取消") {
					if (this.childrenData != undefined && this.childrenData.length > 1) {
						for (var i = 0; i < this.childrenData.length; i++) {
							if (this.childrenData[i].schoolCode == this.tableData[index].newSchoolid) {
								this.childrenData.splice(i, 1);
							}
						}
						this.tableData[index].schemeName = null
					}else{
						this.$message({
							message: '请至少选择一个志愿！',
							type: 'warning'
						});
						throw Error;
					}
				}else if(val=="收藏"){
					// for (var z = 0; z < this.childrenData.length; z++) {
					// 	if (this.childrenData[z].schoolCode == this.tableData[index].newSchoolid) {
					// 		this.childrenData.splice(z, 1);
					// 	}
					// }
						this.childrenData.push({
							"schemeName": val,
							"schoolName": this.tableData[index].schoolName,
							"schoolCode": this.tableData[index].newSchoolid
						})
					
					this.tableData[index].schemeName = val
					console.log("数据"+JSON.stringify(this.childrenData))
				}
				this.saveScheme()
			},
			natureclick(e,t){
				if(e==='不限'){
					this.checkedNatures=['不限']
				}else{
					this.checkedNatures.forEach(i=>{
						if(i=='不限'){
							this.checkedNatures.splice(this.checkedNatures.indexOf(i),1)
						}
					})
					if(t==false&&this.checkedNatures.length<1){
						this.checkedNatures=['不限']
					}
				}
			},
			hierarchysclick(e,t){
				if(e==='不限'){
					this.checkedHierarchys=['不限']
				}else{
					this.checkedHierarchys.forEach(i=>{
						if(i=='不限'){
							this.checkedHierarchys.splice(this.checkedHierarchys.indexOf(i),1)
						}
					})
					if(t==false&&this.checkedHierarchys.length<1){
						this.checkedHierarchys=['不限']
					}
				}
			},
			qualificationsclick(e,t){
				if(e==='不限'){
					this.checkedQualifications=['不限']
				}else{
					this.checkedQualifications.forEach(i=>{
						if(i=='不限'){
							this.checkedQualifications.splice(this.checkedQualifications.indexOf(i),1)
						}
					})
					if(t==false&&this.checkedQualifications.length<1){
						this.checkedQualifications=['不限']
					}
				}
			},
			schooltypeclick(e,t){
				if(e==='不限'){
					this.checkedSchoolTypes=['不限']
				}else if(e=='其他'){
					this.checkedSchoolTypes=['其他']
				}else{
					this.checkedSchoolTypes.forEach(i=>{
						if(i=='不限'||i=='其他'){
							this.checkedSchoolTypes.splice(this.checkedSchoolTypes.indexOf(i),1)
						}
					})
					if(t==false&&this.checkedSchoolTypes.length<1){
						this.checkedSchoolTypes=['不限']
					}
				}
			},
			sfclick(e,t){
				if(e==='不限'){
					this.checkedCities=['不限']
				}else if(e==='其他'){
					this.checkedCities=['其他']
				}else{
					this.checkedCities.forEach(i=>{
						if(i=='不限'||i=='其他'){
							this.checkedCities.splice(this.checkedCities.indexOf(i),1)
						}
					})
					if(t==false&&this.checkedCities.length<1){
						this.checkedCities=['不限']
					}
				}
			},
			// 单元格的 style 的回调方法
			cellStyle({
				row,
				column,
				rowIndex,
				columnIndex
			}) {
				if (columnIndex === 1||columnIndex==2) {
					return `textAlign:left;`
				}else if (columnIndex === 0) {
					return `textAlign:center;color:#1264ff`
				}else {
						return 'textAlign:center;'
				}
			},
			cellStyles({
				row,
				column,
				rowIndex,
				columnIndex
			}) {
				if(row.color=="red"){
					if (columnIndex === 1||columnIndex==2) {
						return `textAlign:left;color:red;backgroundColor:#fff2f3`
					}else {
						if(columnIndex==6){
							return 'textAlign:center;backgroundColor:#fff2f3'
						}
							return 'textAlign:center;color:red;backgroundColor:#fff2f3'
					}
				}else{
					if (columnIndex === 1||columnIndex==2) {
						return `textAlign:left;backgroundColor:#fff2f3`
					}else {
							return 'textAlign:center;backgroundColor:#fff2f3'
					}
				}
				
			},
			createFilter(queryString) {
			        return (restaurant) => {
			          return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) !== -1);
			        };
			      },
			querySearch(queryString, cb) {
			        var restaurants = this.options;
			        var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
			        // 调用 callback 返回建议列表的数据
			        cb(results);
			      },
			querySearch1(queryString, cb) {
			        var restaurants = this.schoolNames;
			        var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
			        // 调用 callback 返回建议列表的数据
			        cb(results);
			      },
			condition(){
				if(this.activeName=='first'){
					this.checkedCities = ['不限']
					this.checkedSchoolTypes = ['不限']
					this.checkedNatures = ['不限']
					this.checkedHierarchys = ['不限']
					this.checkedQualifications=['不限']
					this.arrangement='1'
					this.cchoice=['H','S']
					this.schoice='W'
					this.courseRequire=[]
					this.major = null
					this.school = null
				}else{
					this.checkedCities = ['不限']
					this.checkedSchoolTypes = ['不限']
					this.checkedNatures = ['不限']
					this.checkedHierarchys = ['不限']
					this.checkedQualifications=['不限']
					this.arrangement=''
					this.courseRequire=[]
					this.cchoice=[]
					this.schoice=null
					this.major = null
					this.school = null
				}
				this.getNewSchool()
			},
			getyaoqiu() {
				request({
					method: 'Get',
					url: 'sysDict/getDict',
					params: {
						dictType: 'course_require_type'
					}
				}).then(res => {
					this.yaoqiu = res.data
				})
			},
			getNewSchool() {
				if(this.activeName=='first'&&this.cchoice.length<2){
					this.$message({
						message: '再选科目不得少于两个！',
						type: 'warning'
					});
					return false;
				}
				this.loading = true
				var hierarchys="";
				if(this.checkedHierarchys.length>0){
					for(var i=0;i<this.checkedHierarchys.length;i++){
						if(i<this.checkedHierarchys.length-1){
							hierarchys+=this.checkedHierarchys[i]+"|";
						}else{
							hierarchys+=this.checkedHierarchys[i];
						}
					}
				}		
				var qualifications="";
				if(this.checkedQualifications.length>0){
					for(var i=0;i<this.checkedQualifications.length;i++){
						if(i<this.checkedQualifications.length-1){
							qualifications+=this.checkedQualifications[i]+"|";
						}else{
							qualifications+=this.checkedQualifications[i];
						}
					}
				}
				if(this.checkedCities=='不限'){
					this.pageObject.city=[]
				}else{
					this.pageObject.city = this.checkedCities
				}
				if(this.checkedNatures=='不限'){
					this.pageObject.nature=[]
				}else{
					this.pageObject.nature = this.checkedNatures
				}
				if(this.checkedHierarchys=='不限'){
					this.pageObject.hierarchys=''
				}else{
					this.pageObject.hierarchys = hierarchys
				}
				if(this.checkedSchoolTypes=='不限'){
					this.pageObject.type=[]
				}else{
					this.pageObject.type = this.checkedSchoolTypes
				}
				if(this.checkedQualifications=='不限'){
					this.pageObject.qualifications=''
				}else{
					this.pageObject.qualifications = qualifications	
				}
				
				this.pageObject.major=this.major
				this.pageObject.school=this.school
				this.pageObject.courseRequire=this.courseRequire
				this.pageObject.arrangement=this.arrangement
				this.pageObject.schoice=this.schoice
				this.pageObject.cchoice=this.cchoice
				const _this = this
				this.Submit = 1;
				request({
					method: 'post',
					url: 'electiveCourseInfo/getXingaokao',
					data: this.pageObject
				}).then(res => {
					if(res.code==0||res.code==200){
						res.data.forEach(i => i.schemeName = "")
						if (this.tableData) {
							for (var i = 0; i < res.data.length; i++) {
								this.childrenData.forEach(j => {
									if (res.data[i].newSchoolid == j.schoolCode) {
										res.data[i].schemeName = j.schoolName
										if(j.majorList!=null&&j.majorList!=undefined&&j.majorList!=""){
											for (var r = 0; r < j.majorList.length; r++) {
												// res.data[i].children.forEach(o => {
												// 	if (j.majorList[r].id == o.id) {
												// 		o.sort = j.majorList[r].sort
												// 	}
												// })
											}
										}
									}
								})
							}
							this.tableData = res.data
							this.count=res.data.length
						} else {
							this.tableData = res.data
							this.count=res.data.length
						}
					}
					this.loading = false
					
				})
			},
			getMajorName() {
				request({
					method: 'Get',
					url: 'electiveCourseInfo/getMajorName'
				}).then(res => {
					this.options = res.data
				})
			},
			getSchoolName() {
				request({
					method: 'Get',
					url: 'electiveCourseInfo/getSchoolName'
				}).then(res => {
					this.schoolNames = res.data
				})
			},
			stopF5Refresh() {
			      document.onkeydown = function (e) {
			        var evt = window.event || e;
			        var code = evt.keyCode || evt.which;
			        //屏蔽F1---F12
			        if (code > 111 && code < 124) {
			          if (evt.preventDefault) {
			            evt.preventDefault();
			          } else {
			            evt.keyCode = 0;
			            evt.returnValue = false;
			          }
			        }
			      };
			      //禁止鼠标右键菜单
			      document.oncontextmenu = function () {
			        return false;
			      };
			    },
		},
		mounted() {
		},
		created() {
			this.stopF5Refresh();
			if (JSON.parse(this.$route.query.programme != null)) {
				this.dialogVisible=false
				this.programmes = JSON.parse(this.$route.query.programme)
				this.childrenData = [...this.programmes]
			}else{
				let newlist={
						"schemeType": 1,
						"schemeChange": "0",
						"sort": 1,
			}
			this.programmes.push(newlist)
			this.childrenData=this.programmes
			}
			const user = localStorage.getItem("stu");
			this.user = JSON.parse(user)
			this.getMajorName()
			this.getSchoolName()
			this.getyaoqiu()
			this.getNewSchool()
			this.stuId=this.user.id
		}
	};
</script>

<style>
	#xgks input{
		height: 28px;
	}
	#xgks .el-input__icon{
		line-height: 28px;
	}
	#xgks .d2 {
		width: 1300px;
		min-width: 1300px;
		margin: auto;
	}
	.qux{
		color: orangered;
	}
	
	#xgks th {
		font-weight: 500;
		height: 50px;
		border: 1px #68696a solid;
	}
	#xgks .btn {
		width: 80px;
		height: 30px;
		background-color: coral;
		color: #fff;
		-moz-border-radius: 10px;
		-webkit-border-radius: 10px;
		border-radius: 10px;
		-khtml-border-radius: 10px;
		text-align: center;
		border: 1px solid transparent;
		font-weight: 900;
		margin-top: 10px;
		margin-left: 1px;
		font-size: 15px;
		border-radius: 5px;
	}
	#xgks .d2 ul {
		list-style: none;
		display: inline-block;
		padding: 0;
		margin: 0;
	}
	
	#xgks .d2 ul li {
		display: inline-block;
		margin-left: 2px;
		font-size: 15px;
	}
	#xgks #fx .el-checkbox__input {
		display: none;
	}
	#xgks .has-gutter .cell {
		padding: 0;
		color: black;
	}
	
	#xgks .el-table__row td div {
		padding: 0;
	}
	
	#xgks .el-table__row td {
		padding: 0;
		height: 35px;
	}
	
	#xgks .has-gutter th {
		padding: 0;
		height: 35px;
	}
	
	#xgks .cell{
		padding: 0;
	}
	
	.establishBtn{
		padding: 0;
		text-align: center;
	}
	
	.establishBtn span {
		display: inline-block;
		margin-left: 5px;
	}
	#xgks .el-radio{
		margin-right: 10px;
	}
	#xgks #xk .el-checkbox{
		margin-right: 10px;
	}
/* 	#xgks #table .el-table__header-wrapper{
		display: none;
	} */
	#xgks .el-table__cell {
		padding: 0rem 0rem 0rem 0rem;
	}
	.el-checkbox__label{
		font-size: 15px;
	}
	#xgks .el-radio__label{
		font-size: 15px;
	}
	#xgks .el-tabs__item{
		font-size: 15px;
	}
	#xgks .el-form-item__label{
		font-size: 15px;
		color: #000000;
	}
	#xgks .el-checkbox{
		font-size: 15px;
		color: black;
	}
</style>
